package com.wowudi.web.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.dto.ListDto;
import com.wowudi.entity.HoPay;
import com.wowudi.entity.Patients;
import com.wowudi.service.*;
import com.wowudi.util.MsgUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("api/fina/hopay")
public class HoPayController {
    @Autowired
    private HoPayService hoPayService;
    @Autowired
    private PatientsService patientsService;
    @RequestMapping("findhopay")
    public Page<HoPay> findPati(Integer pageym , Integer pagesize, String cartid, String patiname) {
        Page<HoPay> page = new Page<HoPay>(pageym,pagesize);
        //this.hoPayService.page(page);
         this.hoPayService.getAllBynameandid(page,cartid,patiname);
        return page;
    }

    //添加
    @RequestMapping("addHopay")
    public MsgUtil addPati(@RequestBody HoPay hoPay) {
        hoPay.setHpCreateTime(new Date());
        hoPay.setHpIsdel(0);
        Boolean bool=this.hoPayService.save(hoPay);
       // Integer bool=this.doctorAdviceService.addDoct(doctorAdvice,list);
        if (bool){
            return new MsgUtil(true,"添加成功",null);
        }else {
            return new MsgUtil(false,"添加失败",null);
        }
    }
    //删除
    @RequestMapping("delHopay")
    public MsgUtil delPati(Integer id) {
        HoPay hoPay=this.hoPayService.getById(id);
        hoPay.setHpIsdel(1);
        boolean bool=this.hoPayService.updateById(hoPay);
        if (bool){
            return new MsgUtil(true,"删除成功",null);
        }else {
            return new MsgUtil(false, "删除失败", null);
        }
    }
    @RequestMapping("getListDto")
    public ListDto getListDto() {
        ListDto listDto=new ListDto();
        listDto.setPackageList(this.patientsService.list());
        return listDto;
    }
    //修改
    @RequestMapping("upHopay")
    public MsgUtil upHopay(@RequestBody HoPay hoPay) {
        boolean bool=this.hoPayService.updateById(hoPay);
        if (bool){
            return new MsgUtil(true,"修改成功",null);
        }else {
            return new MsgUtil(false, "修改失败", null);
        }
    }
    //显示修改ui
    @RequestMapping("upHopayui")
    public HoPay upPatiui(Integer id) {
        HoPay hoPay=this.hoPayService.getById(id);
        return hoPay;
    }
}
